import Vue from 'vue';
import Vuex from 'vuex';
import {
		Session
	} from '@/utils/storage';
Vue.use(Vuex);

const state = {
	token: Session.get('token') || ''
}
const mutations = {
	setToken(state, value) {
		state.token = value
	}
}

let moduleFn = require.context('./modules', false, /\.js$/);
let modules = moduleFn.keys().reduce((p, c) => {
	let mod = moduleFn(c).default;
	mod = {
		...mod,
		namespaced: true
	};
	let modName = c.match(/\.\/(\w+)\.js$/)[1];
	p[modName] = mod;
	return p;
}, {});

export default new Vuex.Store({
	modules,
	state,
	mutations,
});